# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

pkgname=('nettle' 'libnettle' 'libhogweed' 'libnettle-devel')
pkgver=3.1.1
pkgrel=1
pkgdesc="A low-level cryptographic library"
arch=('i686' 'x86_64')
url="http://www.lysator.liu.se/~nisse/nettle/"
license=('GPL2')
groups=('net-utils')
depends=('gmp')
makedepends=('gmp-devel')
source=(http://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.gz{,.sig}
        2.6-soname.patch
        nettle-2.6-msys2.patch)
md5sums=('b40fa88dc32f37a182b6b42092ebb144'
         'SKIP'
         '3c2d04c506a4eb916e84dd654455bf33'
         'b70f9ee2a142fb18f469ef36289607e9')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  patch -p2 -i ${srcdir}/2.6-soname.patch
  patch -p1 -i ${srcdir}/nettle-2.6-msys2.patch

  autoreconf -fi
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  ./configure \
    --prefix=/usr \
    --libdir=/usr/lib \
    --build=${CHOST} \
    --enable-shared \
    --enable-static \
    --disable-assembler

  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make -k check
}

package_nettle() {
  depends=('libnettle')
  install=$pkgname.install

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin/*.exe ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_libnettle() {
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin/*nettle*.dll ${pkgdir}/usr/bin/
}

package_libhogweed() {
  groups=('libraries')
  depends=('gmp' 'libnettle')

  mkdir -p ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/bin/*hogweed*.dll ${pkgdir}/usr/bin/
}

package_libnettle-devel() {
  pkgdesc="Libnettle headers and libraries"
  groups=('development')
  options=('staticlibs')
  depends=("libnettle=${pkgver}" "libhogweed=${pkgver}" 'gmp-devel')

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
